package iniitialize

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"week2/AppConfig"
	"week2/types"
)

var (
	err error
)

func InitMysql() {
	AppMysql := AppConfig.AppConf.MysqlConfig
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", AppMysql.User, AppMysql.Pwd, AppMysql.Host, AppMysql.Port, AppMysql.Database)
	types.Db, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		panic("Mysql数据库配置文件连接失败")
		return
	}
	fmt.Println("Mysql数据库配置文件连接成功")

	fmt.Println(dsn)
}
